##########################################################################
#  Copyright (C) 2007 Robert Connolly <rob_connolly@mailshack.com>       #
#                                                                        #
#  This program is free software; you can redistribute it and/or modify  #
#  it under the terms of the GNU General Public License as published by  #
#  the Free Software Foundation; either version 3 of the License, or     #
#  (at your option) any later version. See file COPYING for details.     #
#                                                                        #
#  This program is distributed in the hope that it will be useful,       #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#  GNU General Public License for more details.                          #
#                                                                        #
#  You should have received a copy of the GNU General Public License     #
#  along with this program; if not, write to the                         #
#  Free Software Foundation, Inc.,                                       #
#  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
##########################################################################

import datetime

from cairolets.core import Sensor

class ClockSensor(Sensor):
	"""<name>ClockSensor</name>
	   <description>A Very Simple Clock Sensor</description>
	   <author email='rob_connolly@mailshack.com'>Robert Connolly</author>
	   <website>http://cairolets.googlecode.com</website>"""

	def __init__(self):
		now = datetime.datetime.now()
		
		start_time = {'second': now.second, 'minute': now.minute, 'hour': now.hour, 'day': now.day, 'month': now.month, 'year':  now.year}
		
		Sensor.__init__(self, start_time)
	
	def do_step(self):
		now = datetime.datetime.now()
		
		self.edit_data('second', now.second)
		
		if now.second == 0:
			self.edit_data('minute', now.minute)
			
		if now.minute == 0:
			self.edit_data('hour', now.hour)
			
		if now.hour == 0:
			self.edit_data('day', now.day)
			
		if now.day  == 1:
			self.edit_data('month', now.month)
			
		if now.month == 1:
			self.edit_data('year', now.year)
		
		return True
